package com.lanou.quanttrade.stock.controller;

import com.lanou.quanttrade.stock.javabean.MemberDailyStrategy;
import com.lanou.quanttrade.stock.javabean.MemberDailyStrategyTable;
import com.lanou.quanttrade.stock.service.StockService;
import com.lanou.quanttrade.utils.javabean.RestObject;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/stock")
@CrossOrigin(allowCredentials = "true",allowedHeaders = "*") //跨域在开发环境可以有，在生产环境中尽可能去除
public class StockController {
    @Autowired
    private StockService stockService;

    @ApiOperation("首页推荐接口")
    @PostMapping("/homeSell")
    public @ResponseBody RestObject homeSell(){
        //查询并返回推荐的三只股票
        return stockService.recommendStocksThroughBias();
    }
    @ApiOperation("echarts图表数据接口")
    @PostMapping("/imgData")
    public @ResponseBody RestObject imgData(@RequestBody Map<String,Object> map){
        Object code = map.get("code");
        if(code==null)
            return RestObject.ERROR("查询失败，必须要有股票代码");
        //根据股票stockcode查询echarts图表需要的数据并返回
        return stockService.getImgData(code.toString());
    }
    @ApiOperation("市场表现研究策略添加接口")
    @PostMapping("/sendSell")
    public @ResponseBody RestObject sendSell(@RequestBody MemberDailyStrategy memberDailyStrategy, HttpSession session){
        //调用service，保存策略信息，并将策略 id 返回给前端
        return stockService.saveMemberDailyStrategy(memberDailyStrategy,session);
    }

    @ApiOperation("市场表现研究策略添加-策略列表保存接口")
    @PostMapping("/sendList")
    public @ResponseBody RestObject sendList(@RequestBody MemberDailyStrategyTable memberDailyStrategyTable){
        //调用service，保存某个策略的 策略展示列表，并将保存结果返回给前端
        return stockService.saveMemberDailyStrategyTable(memberDailyStrategyTable);
    }
    @ApiOperation("市场表现研究策略左侧策略列表展示-接口")
    @PostMapping("/leftList")
    public @ResponseBody RestObject leftList(HttpSession session){
        //调用service，查询该用户的策略列表，并返回前端
        return stockService.getMemberDailyStrategysThroughMid(session);
    }

    @ApiOperation("乖离率&市场表现研究策略列表展示-接口")
    @PostMapping("/gll")
    public @ResponseBody RestObject gll(@RequestBody Map<String,String> paramMap){
        return stockService.getMemberDailyStrategyDatas(paramMap);
    }
}
